home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH8 / SRC / SIERP3.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-07  |  3.4 KB  |  117 lines

  1. VERSION 4.00
  2. Begin VB.Form Sierp3Form 
  3.    Caption         =   "Sierpinski Gasket"
  4.    ClientHeight    =   4335
  5.    ClientLeft      =   2280
  6.    ClientTop       =   1185
  7.    ClientWidth     =   5070
  8.    Height          =   5025
  9.    Left            =   2220
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   289
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   338
  14.    Top             =   555
  15.    Width           =   5190
  16.    Begin VB.TextBox LevelText 
  17.       Height          =   285
  18.       Left            =   600
  19.       MaxLength       =   3
  20.       TabIndex        =   0
  21.       Text            =   "5"
  22.       Top             =   0
  23.       Width           =   375
  24.    End
  25.    Begin VB.PictureBox Canvas 
  26.       AutoRedraw      =   -1  'True
  27.       Height          =   4335
  28.       Left            =   1080
  29.       ScaleHeight     =   285
  30.       ScaleMode       =   3  'Pixel
  31.       ScaleWidth      =   261
  32.       TabIndex        =   3
  33.       Top             =   0
  34.       Width           =   3975
  35.    End
  36.    Begin VB.CommandButton CmdGo 
  37.       Caption         =   "Go"
  38.       Default         =   -1  'True
  39.       Height          =   495
  40.       Left            =   120
  41.       TabIndex        =   1
  42.       Top             =   480
  43.       Width           =   735
  44.    End
  45.    Begin VB.Label Label1 
  46.       Caption         =   "Level"
  47.       Height          =   255
  48.       Index           =   0
  49.       Left            =   0
  50.       TabIndex        =   2
  51.       Top             =   0
  52.       Width           =   495
  53.    End
  54.    Begin VB.Menu mnuFile 
  55.       Caption         =   "&File"
  56.       Begin VB.Menu mnuFileExit 
  57.          Caption         =   "E&xit"
  58.       End
  59.    End
  60. Attribute VB_Name = "Sierp3Form"
  61. Attribute VB_Creatable = False
  62. Attribute VB_Exposed = False
  63. Option Explicit
  64. Const PI = 3.14159
  65. Dim TheLevel As Integer
  66. ' Maximum space the curve can take up.
  67. Dim TotalLength As Single
  68. Dim StepLength As Single
  69. Dim StartX As Integer
  70. Dim StartY As Integer
  71. ' ************************************************
  72. ' Draw a gasket-like Sierpinski curve.
  73. ' ************************************************
  74. Sub Sierp(level As Integer, theta As Single, dist As Single, turn As Single)
  75.     If level > 0 Then
  76.         Sierp level - 1, theta + turn, dist / 2, -turn
  77.         Sierp level - 1, theta, dist / 2, turn
  78.         Sierp level - 1, theta - turn, dist / 2, -turn
  79.     Else
  80.         Canvas.Line -Step(dist * Cos(theta), dist * Sin(theta))
  81.     End If
  82. End Sub
  83. Sub GetParameters()
  84.     If Not IsNumeric(LevelText.Text) Then _
  85.         LevelText.Text = "5"
  86.     TheLevel = CInt(LevelText.Text)
  87. End Sub
  88. Private Sub CmdGo_Click()
  89. Dim i As Integer
  90.     MousePointer = vbHourglass
  91.     DoEvents
  92.     ' Get the parameters.
  93.     GetParameters
  94.     ' Draw the curve.
  95.     Canvas.Cls
  96.     Canvas.CurrentX = StartX
  97.     Canvas.CurrentY = StartY
  98.     Sierp TheLevel, 0, TotalLength, -PI / 3
  99.     MousePointer = vbDefault
  100. End Sub
  101. Private Sub Form_Resize()
  102.     Canvas.Move Canvas.Left, 0, _
  103.         ScaleWidth - Canvas.Left, ScaleHeight - 1
  104.     ' See how big we can make the curve.
  105.     If Canvas.ScaleHeight < Canvas.ScaleWidth Then
  106.         TotalLength = 0.9 * Canvas.ScaleHeight
  107.     Else
  108.         TotalLength = 0.9 * Canvas.ScaleWidth
  109.     End If
  110.     ' Compute the upper left corner.
  111.     StartX = Canvas.ScaleWidth * 0.05
  112.     StartY = Canvas.ScaleHeight * 0.95
  113. End Sub
  114. Private Sub mnuFileExit_Click()
  115.     Unload Me
  116. End Sub
  117.